#pragma once

#include "IPrimitive.h"
//#include "CMatrix.h"
//#include "CVector3f.h"

class CPrimCylinder : public IPrimitive
{
private:
	float m_radius;
	float m_height;

public:
	CPrimCylinder(float radius, float height);
	~CPrimCylinder();
	

	bool intersect(const CRay& ray, float& dist, bool useGlobalCoordinates);
	void computeNormal(const CRay& ray, float dist, CVector3f& normal)const;
	bool isInside(const CVector3f& p)const;


private:
	bool isValideHeight(float h)const;
	bool calculateTFromHeight(const CRay& ray, float* t)const;
	float calculateTTopEnd(const CRay& R)const;
	float calculateTBottomEnd(const CRay& R)const;
	float fmin(float f1, float f2)const;
};